﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using BusinessLogicLayer;
using Entities;

namespace QLNhaSach.Modules.ThongTin
{
    public partial class DanhSachBaoCaoTon : UserControl
    {
        DataTable table = new DataTable();
        public DanhSachBaoCaoTon()
        {
            InitializeComponent();
            table.Columns.Add("STT");
            table.Columns.Add("Tháng");
            table.Columns.Add("Năm");
            table.Columns.Add("Tên sách");
            table.Columns.Add("Tồn đầu");
            table.Columns.Add("Phát sinh");
            table.Columns.Add("Tồn cuối");
            SachBO sbo = new SachBO();
            BaoCaoTonBO bctbo = new BaoCaoTonBO();
            DataTable dt = bctbo.layDanhSachBaoCaoTon();
            int i = 1;
            foreach (DataRow dr in dt.Rows)
            {
                Sach s = new Sach();
                s = sbo.GetSachByID(int.Parse(dr["CTBCT_MASACH"].ToString()));
                table.Rows.Add(i++, dr["BCT_THANG"].ToString(), dr["BCT_NAM"].ToString(), s.TenSach, dr["CTBCT_TONDAU"].ToString(), dr["CTBCT_PHATSINH"].ToString(), dr["CTBCT_TONCUOI"].ToString());
            }
            gridControl1.DataSource = table;
        }

        private void simpleButton7_Click(object sender, EventArgs e)
        {
            Environment.Exit(1);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            gridControl1.DataSource = null;
            DataTable dt = new DataTable();
            dt.Columns.Add("STT");
            dt.Columns.Add("Tháng");
            dt.Columns.Add("Năm");
            dt.Columns.Add("Tên sách");
            dt.Columns.Add("Tồn đầu");
            dt.Columns.Add("Phát sinh");
            dt.Columns.Add("Tồn cuối");
            SachBO sbo = new SachBO();
            BaoCaoTonBO bctbo = new BaoCaoTonBO();
            DataTable ds = bctbo.layDanhSachBaoCaoTon();
            int i = 1;
            foreach (DataRow dr in ds.Rows)
            {
                Sach s = new Sach();
                s = sbo.GetSachByID(int.Parse(dr["CTBCT_MASACH"].ToString()));
                dt.Rows.Add(i++, dr["BCT_THANG"].ToString(), dr["BCT_NAM"].ToString(), s.TenSach, dr["CTBCT_TONDAU"].ToString(), dr["CTBCT_PHATSINH"].ToString(), dr["CTBCT_TONCUOI"].ToString());
            }
            gridControl1.DataSource = dt;
        }
    }
}
